{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 10, 'x': 'dsc'}\n",
      "{'x': 10, 'y': 10}\n",
      "{3: None, 1: None, 'x': None, 4: None}\n"
     ]
    }
   ],
   "source": [
    "# 初始化\n",
    "a = {1: 10, 'x': 'dsc'}\n",
    "b = dict(x=10,y=10)\n",
    "c = dict.fromkeys({1,3,4,'x'})\n",
    "print(a)\n",
    "print(b)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'x': 100, 'y': 200, 'z': 100}\n",
      "100\n",
      "{'y': 200}\n",
      "{'y': 200, 'x': 1}\n",
      "{'y': 200, 'x': 1, 'a': None}\n"
     ]
    }
   ],
   "source": [
    "#  1. 增\n",
    "a = {'x': 100, 'y': 200}\n",
    "a['z'] = 100\n",
    "print(a)\n",
    "# 2. 删 pop popitem\n",
    "print(a.pop('x'))    # key不存在就报错\n",
    "a.popitem()          # 随意删除一项 \n",
    "print(a)\n",
    "# 3. 改\n",
    "a.update(x=1)         \n",
    "print(a)\n",
    "# 4. 查\n",
    "a.get('x', None) \n",
    "\n",
    "a.setdefault('a')\n",
    "print(a)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('opencv')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "b04e532e6ce11d72ca7f2113c964d7a5531c18c5e6d3e97b1c42c6f9a3724305"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
